//
//  MyOrderBottomCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2018/1/11.
//  Copyright © 2018年 beisheng. All rights reserved.
//

#import "MyOrderBottomCell.h"
#import "PayButtonModel.h"
@interface MyOrderBottomCell ()
@property (weak, nonatomic) IBOutlet UILabel *leftLabel;

@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *priceTextLabel;
@property (weak, nonatomic) IBOutlet UIButton *rightOneBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightTwoBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightThreeBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomBgH;

@property (weak, nonatomic) IBOutlet UIView *bottomBgView;

@end

@implementation MyOrderBottomCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.leftLabel.textColor = darkGray;
    
    self.leftLabel.font = MYFONT(15);
    
    self.priceTextLabel.font = MYFONT(15);
    
    self.priceTextLabel.textColor = darkGray;
    
    self.priceTextLabel.text = @"总价:";
    
    self.priceLabel.textColor = [UIColor redColor];
    
    self.priceLabel.font = MYFONT(17);
    
    self.rightOneBtn.layer.cornerRadius = 5.0;
    
    self.rightOneBtn.layer.masksToBounds = YES;
    
    self.rightTwoBtn.layer.cornerRadius = 5.0;
    
    self.rightTwoBtn.layer.masksToBounds = YES;
    
    self.rightThreeBtn.layer.cornerRadius = 5.0;
    
    self.rightThreeBtn.layer.masksToBounds = YES;
    
    [self.rightOneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.rightOneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    
    [self.rightTwoBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.rightTwoBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    
    [self.rightThreeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.rightThreeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    
    self.rightOneBtn.titleLabel.font = MYFONT(16);
    self.rightTwoBtn.titleLabel.font = MYFONT(16);
    self.rightThreeBtn.titleLabel.font = MYFONT(16);
    
    self.bottomMargin.constant = 0;


    // Initialization code
}

- (void)setModel:(MyOrderSectionModel *)model{
    _model = model;
    
    if ([_model.order_status isEqualToString:@"1"] || [_model.order_status isEqualToString:@"-1"] || !(_model.member_operation.count > 0)) {
        self.bottomBgView.hidden = YES;
        self.bottomBgH.constant = 0;
    } else {
        self.bottomBgView.hidden = NO;
        self.bottomBgH.constant = 52;
        
        if (_model.member_operation.count == 1) {
            self.rightOneBtn.hidden = NO;
            self.rightTwoBtn.hidden = YES;
            self.rightThreeBtn.hidden = YES;
            [self.rightOneBtn setTitle:_model.member_operation.firstObject.name forState:UIControlStateNormal];
            [self.rightOneBtn setTitle:_model.member_operation.firstObject.name forState:UIControlStateHighlighted];
            
//            NSLog(@"%@",_model.member_operation.firstObject.color);
            
            self.rightOneBtn.backgroundColor = [UIColor colorWithHexString:_model.member_operation.firstObject.color];
            
//            self.rightOneBtn.backgroundColor = [UIColor purpleColor];


        } else if (_model.member_operation.count == 2) {
            self.rightOneBtn.hidden = NO;
            self.rightTwoBtn.hidden = NO;
            self.rightThreeBtn.hidden = YES;
            
            [self.rightOneBtn setTitle:_model.member_operation.firstObject.name forState:UIControlStateNormal];
            [self.rightOneBtn setTitle:_model.member_operation.firstObject.name forState:UIControlStateHighlighted];
            
            self.rightOneBtn.backgroundColor = [UIColor colorWithHexString:_model.member_operation.firstObject.color];
            
            
            [self.rightTwoBtn setTitle:_model.member_operation.lastObject.name forState:UIControlStateNormal];
            [self.rightTwoBtn setTitle:_model.member_operation.lastObject.name forState:UIControlStateHighlighted];
            
            self.rightTwoBtn.backgroundColor = [UIColor colorWithHexString:_model.member_operation.lastObject.color];
            
            
            
        }else if (_model.member_operation.count == 3) {
            self.rightOneBtn.hidden = NO;
            self.rightTwoBtn.hidden = NO;
            self.rightThreeBtn.hidden = NO;
            
            [self.rightOneBtn setTitle:_model.member_operation.firstObject.name forState:UIControlStateNormal];
            [self.rightOneBtn setTitle:_model.member_operation.firstObject.name forState:UIControlStateHighlighted];
            
            self.rightOneBtn.backgroundColor = [UIColor colorWithHexString:_model.member_operation.firstObject.color];
            
            
            [self.rightTwoBtn setTitle:_model.member_operation[1].name forState:UIControlStateNormal];
            [self.rightTwoBtn setTitle:_model.member_operation[1].name forState:UIControlStateHighlighted];
            
            self.rightTwoBtn.backgroundColor = [UIColor colorWithHexString:_model.member_operation[1].color];
            
            
            [self.rightThreeBtn setTitle:_model.member_operation.lastObject.name forState:UIControlStateNormal];
            [self.rightThreeBtn setTitle:_model.member_operation.lastObject.name forState:UIControlStateHighlighted];
            
            self.rightThreeBtn.backgroundColor = [UIColor colorWithHexString:_model.member_operation.lastObject.color];
            
        }else{
            self.rightOneBtn.hidden = YES;
            self.rightTwoBtn.hidden = YES;
            self.rightThreeBtn.hidden = YES;

        }
    }
    
    
    
    if ([_model.order_status isEqualToString:@"-1"]) {//退款
        self.leftLabel.text = @"退款中";
    } else if ([_model.order_status isEqualToString:@"0"]){//待付款
        self.leftLabel.text = @"待付款";

    }else if ([_model.order_status isEqualToString:@"1"]){//待发货
        self.leftLabel.text = @"待发货";

    }else if ([_model.order_status isEqualToString:@"2"]){//已发货
        self.leftLabel.text = @"已发货";

    }else if ([_model.order_status isEqualToString:@"3"]){//已收货
        self.leftLabel.text = @"已收货";

        
    }else if ([_model.order_status isEqualToString:@"5"]){//已关闭
        
        self.leftLabel.text = @"已关闭";

    }else{//已完成4
        
        self.leftLabel.text = @"已完成";

    }
    
    
    self.priceLabel.text = [NSString stringWithFormat:@"%@P",_model.order_money];
    
}


- (IBAction)rightOneBtnDidTap:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(bottomBtnDidClickWith:indexPath:)]) {
        [self.delegate bottomBtnDidClickWith:sender.currentTitle indexPath:self.index];
    }
    
}

- (IBAction)rightTwoBtnDidTap:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(bottomBtnDidClickWith:indexPath:)]) {
        [self.delegate bottomBtnDidClickWith:sender.currentTitle indexPath:self.index];
    }
    
}

- (IBAction)rightThreeBtnDidTap:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(bottomBtnDidClickWith:indexPath:)]) {
        [self.delegate bottomBtnDidClickWith:sender.currentTitle indexPath:self.index];
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
